Nikolay,
I would consider having a value in my app.config/web.config that indicated
if the app itself is a web app or a win forms app. Especially if web or win
determined how a specific routine behaved. The specific routine would be an
overridable method of an abstract base class (a MustInherit class), where
the app.config indicated the specific concrete class to create (basically a
Strategy pattern & Plug-in pattern
http://www.martinfowler.com/eaaCatalog/plugin.html)
My app/dll would only use the StrategyBase abstraction, while there would be
specific implementations for both ASP.NET & Win Forms. This would also allow
defining a Console App & Windows Service strategies also.
I would store the full name of the concrete class that inherits from the
abstract base class in the app.config file. I then use
System.Activator.CreateInstance to create instances of this class. Something
like:
<configuration>
<configSections>
<!-- define a custom config section to keep appSettings clean -->
<sectionGroup name="myCompany">
<sectionGroup name="myProduct">
<section name="myDll"
type="System.Configuration.SingleTagSectionHandler "
/>
</sectionGroup>
</sectionGroup>
</configSections>
<myCompany>
<myProduct>
<!-- the "type" attribute is "namespace.class, assembly" -->
<myDll setting1="Value1" setting2="value two"
type="MyProject.AspNetStrategy, MyProject" />
</myProduct>
</myCompany>
</configuration>
Imports System.Configuration
Public MustInherit Class StrategyBase
Public MustOverride Sub Something()
Public Shared Function GetStrategy() As StrategyBase
Dim myDllConfig As IDictionary
Dim value1 As String
Dim value2 As String
Dim strategyTypeName As String
myDllConfig =
DirectCast(ConfigurationSettings.GetConfig("myComp any/myProduct/myDll"),
IDictionary)
value1 = DirectCast(myDllConfig("setting1"), String)
value2 = DirectCast(myDllConfig("setting2"), String)
strategyTypeName = DirectCast(myDllConfig("type"), String)
Dim strategyType As Type = Type.GetType(strategyTypeName)
Dim strategyObject As Object =
Activator.CreateInstance(strategyType)
Return DirectCast(strategyObject, StrategyBase)
End Function
End Class
Public Class AspNetStrategy
Inherits StrategyBase
Public Overrides Sub Something()
' Do "Something" for ASP.NET apps
End Sub
End Class
Public Class WinFormsStrategy
Inherits StrategyBase
Public Overrides Sub Something()
' Do "Something" for Win Forms apps
End Sub
End Class
In the above "value1" & "value2" could optionally be used as parameters to
the specific StrategyBase object.
See the following on how to create new sections via the configSections
section.
http://msdn.microsoft.com/library/de...onhandlers.asp
and:
http://msdn.microsoft.com/library/de...ionsschema.asp
Also read about the System.Configuration.ConfigurationSettings class and
other classes in the System.Configuration namespace.
Hope this helps
Jay
"Nikolay Petrov" <jo******@mail.bg> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
|I have an class library, which I shared with some of my apps.
| Some of them are Winfroms apps, others are ASP .NET.
| How could I check from a method in my library, is it called form an
| Winforms or ASP .NET?
|
| tnx
|