문제

I have written a little console application that uses s#arp. I can create an executable using the configuration manager and selecting release. I understand that the dlls are needed and that there is apparently no easy way to ‘bind’ (?) everything into one executable:

SO link

Is there at least a way to hide:

NHibernate.config

So that the db’s connection string is hidden? I remember that it is possible to encrypt Web.config for asp.net. Maybe something similar is possible?

Any feedback would be very much appreciated. Many thanks in advance.

도움이 되었습니까?

해결책

You would need to configure the connection string property in code to decrypt, SharpArch provides following overload which allows adding properties to your config:

NHibernateSession.Init(
                sessionStorage,
                new[] { Server.MapPath("~/bin/Suteki.TardisBank.Infrastructure.dll") },
                new AutoPersistenceModelGenerator().Generate(),
                Server.MapPath("~/NHibernate.config"),

                // You can get all the values from your config and use here,
                // if you dont want a config file at all, or just decrypt the 
                // connection string and provide that value dictionary:
                new System.Collections.Generic.Dictionary<string, string>
                    {
                        {
                            NHibernate.Cfg.Environment.ConnectionString, DecryptConnectionString()
                        }
                    }, null);

Where the decrypt method DecryptConnectionString() gets the connection string from wherever you like, be it an encrypted config section from app.config or hard coded string.

As Corbin said, this makes it more complicated for average Joe to figure out the connection string, but it can be done, if you are going to be distributing this then I would look into not connecting to the db directly.

Look into ILMerge if you want 1 executable with dlls inside it.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top